<?php include '_init_.php';?>
<?php include 'page_header.php';?>
<?php
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act == 'save')
{
	
	if(intval($_REQUEST['id']) < 1)
	{
		$orderManager = Order_Manager::createOrderManager();
	}else{
		$orderManager = Order_Manager::getOrderManager($_REQUEST['id']);
		if($orderManager->getStatus() != Order_Manager::$STATUS_CREATING)
		{
			exit("Order doesn't editable");
		}
	}
	if(!$orderManager)
			exit("data not exist");
	$orderManager->init();
	$orderManager->setCustomerInfo($_REQUEST);
	$orderManager->persistOrderInfo();
	
	header('Location:add-cosb.php?id='.$orderManager->getId());
	exit();
}
$id = isset($_REQUEST['id'])?intval($_REQUEST['id']):0;
if($id > 0)
{
	$orderManager = Order_Manager::getOrderManager($_REQUEST['id']);
	if(!$orderManager)
		exit('Data not exist anymore');
	$pageInfo = $orderManager->getCustomerInfo();
}else{
	$pageInfo = array();
}
?>
 <script language="javascript">
    function submitForm()
    {
    	$('.form_value_error').removeClass('form_value_error');
    	var form = document.forms[0];
    	if(form.name.value == '')
    	{
    		alert('請綠入客戶姓名!');
    		$(form.name).addClass('form_value_error');
    		return false;
    	}
    	form.submit();
    	return false;
    }
</script>
<div id="main"><!-- start #main //-->
<form method="post" >
<input type="hidden" name="id" value="<?php echo intval($_REQUEST['id']);?>"/>
<input type="hidden" name="act" value="save"/>
<div id="tita">
  <div class="tita-1">
    <h3>新增客戶資料</h3>
    <img src="images/point-1.gif" width="18" height="18" /> 
    <h4>客戶資料</h4>
    </div>
  <div class="tita-2"></div>
  </div>
  <div id="maine" class="clearfix"><!-- start #maina //-->
  <div class="maine-1">
    <ul>
      <li class="maine-1a">
       姓名<input name="name" type="text" class="maine-keyina" value="<?php echo $pageInfo['name'];?>"/></li>
      <li>
        <p class="maine-1a">生日</p>
        <p class="maine-1a2">民國</p>
        <input name="birthday_year" type="text"  class="maine-keyinb2" value="<?php echo $pageInfo['birthday']['year'];?>"/>
       <p class="maine-1a2">年</p>
        <label for="select2"></label>
        <select name="birthday_month" class="maine-keyinm3">
        <?php
        	for($i = 1; $i < 13; $i++)
        	{
        		if($pageInfo['birthday']['month'] == $i)
        		{
        			printf("<option value='%d' selected>%02d</option>",$i,$i);
        		}else{
        			printf("<option value='%d'>%02d</option>",$i,$i);
        		}
        	}
        ?>
        </select>
        <p class="maine-1a2">月</p> 
        <select name="birthday_date" class="maine-keyinm3" >
        <?php
        	for($i = 1; $i < 32; $i++)
        	{
        		if($pageInfo['birthday']['date'] == $i)
        		{
        			printf("<option value='%d' selected>%02d</option>",$i,$i);
        		}else{
        			printf("<option value='%d'>%02d</option>",$i,$i);
        		}
        	}
        ?>
        </select>
        <p class="maine-1a2">日</p>
        </li>
      <li class="maine-1a">
        電話<input name="tel_part_one" type="text"  class="maine-keyinb" value="<?php echo $pageInfo['tel']['part_one'];?>"/><input name="tel_part_two" type="text"  class="maine-keyine" value="<?php echo $pageInfo['tel']['part_two'];?>"/>
      </li>
      <li class="maine-1a">
       手機<input name="mobile" type="text"   class="maine-keyina" value="<?php echo $pageInfo['mobile'];?>"/>
      </li>
      <li class="maine-1a">
      地址<input name="address_part_one" type="text"  class="maine-keyind" value="<?php echo $pageInfo['address']['part_one'];?>"/><input name="address_part_two" type="text"  class="maine-keyinb" value="<?php echo $pageInfo['address']['part_two'];?>"/><input name="address_part_three" type="text"  class="maine-keyinc" value="<?php echo $pageInfo['address']['part_three'];?>"/></li>
      <li class="maine-1a">電郵1<input name="email" type="text"  class="maine-keyina" value="<?php echo $pageInfo['email'];?>"/></li>
      <li class="maine-1a">電郵2<input name="email2" type="text"  class="maine-keyina" value="<?php echo $pageInfo['email2'];?>"/></li>
    </ul>
    </div>
    </div>
  
    <div id="pagec"><!-- start #pagec //-->
    <div id="pagea-1" ><a href="#" onclick="submitForm();"><img src="images/pagec-next.gif" width="82" height="28" /></a></div>
  </div><!-- end #pagec //-->
</div><!-- end #tita //-->
</form>
</div><!-- end #main //-->
<?php include 'page_footer.php';?>